package com.qianying.controller.admin;

import com.qianying.comment.CommonResult;
import com.qianying.dto.CustomerInfoDTO;
import com.qianying.service.CustomerInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/customer")
@Tag(name = "客户：客户信息管理")
public class CustomerInfoController {

    @Autowired
    private CustomerInfoService customerInfoService;

    @PostMapping("/add")
    @Operation(summary = "新增客户信息")
    public CommonResult<?> addCustomer(@RequestBody @Validated CustomerInfoDTO dto) {
        return customerInfoService.addCustomer(dto);
    }

    @PostMapping("/update")
    @Operation(summary = "根据ID修改客户信息")
    public CommonResult<?> updateCustomer(@RequestBody @Validated CustomerInfoDTO dto) {
        return customerInfoService.updateCustomer(dto);
    }

    @PostMapping("/deleteCustomerById")
    @Operation(summary = "根据客户id删除客户信息")
    public CommonResult<?> deleteCustomerById(Long id) {
        return customerInfoService.deleteCustomerById(id);
    }

    /**
     * 获取客户信息列表
     */
    @PostMapping("/list")
    @Operation(summary = "获取所有的客户信息")
    public CommonResult<?> getCustomerList(@RequestParam(required = false) Long province,
                                           @RequestParam(required = false) Long city,
                                           @RequestParam(required = false) Long district) {
        return customerInfoService.getAllCustomers(province, city, district);
    }
}